
from selenium.webdriver.support.ui import WebDriverWait
class Base():
    # 初始化驱动
    def __init__(self,driver):
        self.driver = driver
    # 封装url
    def open_url(self,url):
        self.driver.get(url)

    # 截图
    def screenshot(self,aa='jietu.png'):
        self.driver.save_screenshot(aa)
    # 封装定位
    def find_element(self,loc):
        try:
            WebDriverWait(self.driver,20,0.5).until(lambda driver: driver.find_element(*loc).is_displayed)
            return self.driver.find_element(*loc)
        except Exception as p:
            print(p)
            print(self.screenshot)
    # 输入框
    def send_keys(self,loc,runs):
        self.find_element(*loc).send_keys(runs)
    # 点击
    def click(self,loc):
        self.find_element(loc).click()

    # 文本
    def text(self,loc):
       return self.find_element(loc).text
    # 弹框处理
    # def handles(self):
    #    return self.switch_to.window(self.driver.window_handles[-1])


